<link rel="stylesheet" type="text/css" href="../addons/jy_meye/resource/css/list.css?v=1">
<style>
.btn.btn-red-o {
	color: red;
	border: 1px solid red;
}
</style>
<div class='fui-page fui-page-current'>
    <div class="fui-content quick" style="margin-bottom:0;padding-bottom:0">
		<div class="fe-floatback" style="left: 4px;">
			<a href="javascript:void(0);" ng-click="goback()">
			<i class="icon icon-back"></i>
			</a>
		</div>
		<div class="fe-floatback" style="position: absolute;width: 8rem;padding:0.3rem 0.2rem;left:50%;margin-left:-4rem;height:1.6rem;border-radius:1.6rem;background-color: #333;color: #fff;line-height: 0.8rem;opacity: 0.6;">
			<div class="overflow-h" style="width:7.6rem;line-height:0.6rem;font-size:0.5rem;"><i class="icon icon-position" style="font-size:0.4rem"></i> {{pagedata.myshop.address || '未定义店铺地址'}}</div>
			<div style="line-height:0.6rem;font-size:0.5rem">{{pagedata.myshop.title || '未定义店铺名称'}}</div>
		</div>
			<div id="carousel-container" class="carousel slide" data-role="carousel" data-param-auto="true">
				<div class="carousel-inner" role="listbox" style="height:6rem">
					<div>
						<a>
							<img ng-src="{{tomedia(pagedata.myshop.topimg) || '../addons/jy_weishop/resource/images/myshoptop.jpg'}}" style="display: block; width: 100%; height: 100%;">
						</a>
					</div>
				</div>
				<style>
						.fui-swipe-page .fui-swipe-bullet {background: {background}; opacity: {opacity};}
						.fui-swipe-page .fui-swipe-bullet.active {opacity: 1;}
				</style>
				<div style="position: absolute;width:100%;height:1rem;margin-top:-1rem;background-color:#fff;border-top-right-radius:100% 1rem;border-top-left-radius:100% 1rem;">
				</div>
			</div>
            <div class="fui-fullHigh-group" style="min-height:20rem">
                <div class="fui-fullHigh-item menu" style="width:4.4rem;padding-top:0.2rem; padding-bottom: 3rem;">
					<nav ng-repeat="item in pagedata.category" ng-click="pagedata.nowckey=$index;pagedata.params.pcate=item.id;pagedata.get_list(true)" ng-class="{'on':pagedata.nowckey==$index}">
						<img style="height:2rem;width:2rem" src="{{tomedia(item.image) || '../core/resource/images/nopic.jpg'}}"/>
						<div ng-class="{'subtitle':1,'red':pagedata.nowckey==$index}" style="line-height:1.4">{{item.title || '未命名'}}</div>
						<div ng-show="item.total" class="dot" style="display: block;">{{item.total}}</div>
					</nav>
				</div>
                <div class="fui-fullHigh-item container" style="padding-bottom: 4rem;">
                    <div ng-repeat="item in pagedata.category" ng-if="pagedata.nowckey==$index" class="quick-list">
						 <div class="fixed-title">
							 <span class="befirst spacing">
								 <span class="icon icon-icon-xiexiantiao" style="color:#efadb0"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#e26d71"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#d62f35"></span>
							 </span> 
							 <span class="title-text">{{item.title || '未命名'}}</span> 
							 <span class="spacing">
								 <span class="icon icon-icon-xiexiantiao" style="color:#d62f35"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#e26d71"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#efadb0"></span>
							 </span>
						 </div>
						 <div class="content-empty" ng-if="!pagedata.goodslist || pagedata.goodslist.length<1">
							  <i class="icon jinyunicon icon-cry" style="width: 6rem;margin-bottom: 0.5rem;"></i><br/><p style="color: #999;font-size: .75rem">暂时没有商品！</p>
						</div>
                        <div id="list">
							    <div class="quick-item small" ng-repeat="(gkey,g) in pagedata.goodslist">
									<a class="thumb" href="javascript:;" ng-click="pagedata.getgoodsdetail(g.id);" data-nocache="true" style="width:6.6rem">
										<img src="{{tomedia(g.image) || '../core/resource/images/nopic.jpg'}}"/>
									</a>
									<div class="info">
										<div class="title bold overflow-h">{{g.title}}</div>
										<div style="font-size:0.55rem"><span style='color:#999;'>已售:{{g.salenum || 0}}</span> <span ng-if="g.isshowtotal==1">库存:{{g.total}}</span></div>
										<div class=""><span ng-if="g.active.price" style='font-size:0.55rem;color:red;'>{{g.active.title}}</span><span class="price red">￥ <span ng-if="!g.active.price" style="font-weight:bold;font-size:1rem;">{{g.price}}</span><span ng-if="g.active.price" style="font-weight:bold;font-size:1rem;">{{g.active.price}}</span> /{{g.unit || '份'}}<span ng-if="!pagedata.pluginset.noweight && g.weight>0" style="color:#999;font-size:0.55rem;font-weight:400">({{g.weight}}kg)</span></span></div>
										<div class="buyline" style="margin-top:0.5rem">
											<div class="buy">
												<div ng-show="g.specs_list.length < 1 && g.total>0" ng-class="{'quick-num':true, 'open':g.carttotal>0}">
													<div ng-click="pagedata.minus(g)" class="minus icon icon-subtract"></div>
													<div class="num" style="color:#999">{{g.carttotal}}</div>
													<div ng-show="g.options.length < 1" ng-click="pagedata.plus(g)" class="plus icon  icon-tianjia"></div>
												</div>
												<div ng-show="g.specs_list.length < 1 && g.total==0" class="quick-num">
													<div class="btn btn-sm btn-red-o order-finish" style="line-height:0.65rem;color:#f60">已售馨</div>
												</div>
												<div ng-show="g.specs_list.length > 0" ng-class="{'quick-num':true, 'open':g.carttotal>0}">
													<div class="btn btn-sm btn-red-o order-finish" style="line-height:0.65rem" onclick="$('#selecttaocan').modal();" ng-click="pagedata.g=g;pagedata.nowgkey=gkey;pagedata.nowckey=$index;" >选规格</div>
													<div ng-show="g.total" class="dot" style="display: block;">{{g.carttotal}}</div>
												</div>
											</div>
										</div>
									</div>
								</div>
						</div>
                    </div>
                </div>
            </div>
	</div>
	<div id="selecttaocan" class="modal fade" tabindex="-1" style="z-index: 99999; display: none;">
					<div class="modal-dialog" style="width:90%;bottom:20%;left:5%;">
						<div class="modal-content" style="border-radius: 0.2rem;padding-top:1rem">
								<div aria-hidden="true" data-dismiss="modal" class="closebtn red" style="top:0.2rem;right:0.2rem"><i class="icon jinyunicon icon-close" style="font-size:1rem"></i></div>
								<div class="fixed-title">
									 <span class="befirst spacing">
										 <span class="icon icon-icon-xiexiantiao" style="color:#efadb0"></span>
										 <span class="icon icon-icon-xiexiantiao" style="color:#e26d71"></span>
										 <span class="icon icon-icon-xiexiantiao" style="color:#d62f35"></span>
									 </span> 
									 <span class="title-text">{{pagedata.g.title}}</span> 
									 <span class="spacing">
										 <span class="icon icon-icon-xiexiantiao" style="color:#d62f35"></span>
										 <span class="icon icon-icon-xiexiantiao" style="color:#e26d71"></span>
										 <span class="icon icon-icon-xiexiantiao" style="color:#efadb0"></span>
									 </span>
								 </div>
								 <div class="subtitle text-center" style="color:#999;font-size:0.6rem">
								 当前: {{pagedata.g.selespename}}
								 </div>
								 <div class="subtitle text-center" style="color:#999;font-size:0.6rem">
								    <span style="margin-right:0.2rem" ng-repeat="p in pagedata.g.post" ng-if="p.num>0">{{p.title}} * <span class="red">{{p.num}}</span></span>
								 </div>
								<div class="row margin0" style="padding-bottom:2.8rem">
									<div ng-repeat="(k,spec) in pagedata.g.specs_list" class="option-picker-cell option spec">
										<div class="fui-cell-group">
											<div class="fui-cell-title subtitle" style="color:#999;font-size:0.6rem">{{spec.title}}</div>
											<div class="fui-cell" style="padding-top:0.2rem">
												<div class="fui-cell-info">
													<span ng-repeat="item in spec.items" ng-class="{'jylabels jylabel-red-o':1,'active':pagedata.g.specid[k]==item.id}" style="line-height:0.8rem;padding: 0.1rem 0.6rem;" ng-click="pagedata.g.specid[k]=item.id;pagedata.get_optionsid();">{{item.title}}</span>
												</div>
											</div>
										</div>
									</div>
								</div>
								<div class="fui-footer quick" style="height:2rem;border-bottom-left-radius: 0.2rem;border-bottom-right-radius: 0.2rem;">
											<div class="quick-info" style="height:2rem">
													<p class="price" style="font-size:0.8rem;line-height:1.2rem">￥{{pagedata.g.options.price || 0.00}}/{{pagedata.g.unit||'份'}}<span ng-if="!pagedata.pluginset.noweight && pagedata.g.options.weight>0" style="color:#f2f2f2;font-size:0.55rem;font-weight:400">({{pagedata.g.options.weight}}kg)</span></p>
											</div>
											<div ng-show="pagedata.g.options.stock>0 && pagedata.g.post[pagedata.g.options.id].num<1" class="quick-submit" style="background:none;height:2rem;margin: 0;font-size:0.65rem;line-height:1.6rem;padding-top:0.4rem" href="javascript:;" ng-click="pagedata.sp_plus(pagedata.g,$index);">
												<div class="bold" style="line-height:1">加入购物车</div>
												<div style="line-height:1">Add to Cart</div>
											</div>
											<div ng-show="pagedata.g.options.stock==0 && pagedata.g.post[pagedata.g.options.id].num<1" class="quick-submit" style="background:none;height:2rem;margin: 0;font-size:0.65rem;line-height:1.6rem;padding-top:0.4rem;color:#f60">
												<div class="bold" style="line-height:1">已售馨</div>
												<div style="line-height:1">Is Sold</div>
											</div>
											<div ng-show="pagedata.g.post[pagedata.g.options.id].num>0"class="quick-submit" style="background:none;height:2rem;margin: 0;font-size:0.8rem;line-height:1.2rem">
													<div class="quick-num open" style="margin-top:0.4rem">
														<div ng-click="pagedata.sp_minus()" class="minus icon icon-subtract" style="background: none; color: #fff; border: 1px solid #fff;font-size: 0.8rem;"></div>
														<div class="num red">{{pagedata.g.post[pagedata.g.options.id].num}}</div>
														<div ng-click="pagedata.sp_plus()" class="plus icon icon-tianjia" style="background: none;border: 1px solid #fff;font-size: 0.8rem;"></div>
													</div>
											</div>
								</div>
								<div class="clear"></div>
						</div>
					</div>
	</div>
	<div ng-if="pagedata.myshop.isrest==0" class="fui-footer quick">
		<p style="font-size:16px;color:#fff;margin-top:8px;width:100%;text-align: center;">商家休息中,暂不接单</p>
	</div>
		<!-- 底部菜单 -->
		<div ng-show="pagedata.showcarts" class="popup">
			<div class="popup-body">
			<div class="popup-bottom">
				<div class="fui-cell-group" style="margin-top:0;padding-top:1rem;margin-bottom:3rem">
					<i ng-click="pagedata.showcarts=false" class="closed icon icon-close red" style="font-size:1rem;"></i>
					<div class="fixed-title">
							 <span class="befirst spacing">
								 <span class="icon icon-icon-xiexiantiao" style="color:#efadb0"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#e26d71"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#d62f35"></span>
							 </span> 
							 <span class="title-text">我的菜单</span> 
							 <span class="spacing">
								 <span class="icon icon-icon-xiexiantiao" style="color:#d62f35"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#e26d71"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#efadb0"></span>
							 </span>
					</div>
					<div ng-repeat="item in pagedata.carts" ng-if="item.total>0" class="fui-cell">
							<div class="fui-cell-text">
								{{item.title}}<span class="subtitle" ng-if="item.optiontitle">({{item.optiontitle}})</span>
							</div>
							<div class="fui-cell-remark noremark">
								<span class="r-f red" style="margin-right:1rem">￥ {{item.price * item.total}} /{{item.unit ||'件'}}<span style="font-size:0.6rem;color:#999" ng-if="item.weight!='0.00'">（{{item.weight}}kg）</span></span>
							</div>
							<div class="fui-cell-remark noremark">
								<div class="quick-num open">
									<div ng-click="pagedata.minus(item,true)" class="minus icon icon-subtract" style="font-size:0.8rem"></div>
									<div class="num" style="color:#333">{{item.total}}</div>
									<div ng-click="pagedata.plus(item,true)" class="plus icon icon-tianjia" style="font-size:0.8rem"></div>
								</div>
							</div>
					</div>
				</div>
				<div ng-if="pagedata.myshop.isrest != 0" class="fui-footer quick">
					<div ng-click="pagedata.showcarts=false" ng-class="{'quick-cart':true,'empty':pagedata.allnum < 1}" style="width:2.3rem">
						<div class="dot" style="display: block;">{{pagedata.allnum}}</div>
						<i class="icon jinyunicon icon-gouwuchexuanzhong" style="line-height:2.5rem;padding:0.3rem 0.5rem;font-size:1.8rem;color:#fff"></i>
					</div>
					<div class="quick-info">
						<p style="color:#fff">￥<span class="price" style="font-weight:400">{{pagedata.showprice}}</span></p>
					</div>
					<div class="quick-submit remark" href="javascript:;" ng-click="access_json('jy_weishop/order.create//storeid='+pagedata.myshop.id)" style="background:none;margin: 0">
						选好了
					</div>
				</div>
			</div>
			</div>
		</div>
		<div ng-if="pagedata.myshop.isrest != 0" class="fui-footer quick">
			<div ng-click="pagedata.showcarts=true" ng-class="{'quick-cart':true,'empty':pagedata.allnum < 1}" style="width:2.3rem">
				<div class="dot" style="display: block;">{{pagedata.allnum}}</div>
				<i class="icon jinyunicon icon-gouwuchexuanzhong" style="line-height:2.5rem;padding:0.3rem 0.5rem;font-size:1.8rem;color:#fff"></i>
			</div>
			<div class="quick-info">
				<p style="color:#fff">￥<span class="price" style="font-weight:400">{{pagedata.showprice}}</span></p>
			</div>
			<div ng-if="pagedata.allnum>0" class="quick-submit remark" href="javascript:;" ng-click="access_json('jy_weishop/order.create//storeid='+pagedata.myshop.id)" style="background:none;margin: 0">
				选好了
			</div>
			<div ng-if="pagedata.allnum==0" class="quick-submit remark" href="javascript:;" style="background:none;margin: 0">
				请添加商品
			</div>
		</div>
		<div class="mask mask-cart"></div>
</div>
<div ng-include="sys_html('shop/_goodsdetail','','','jy_weishop')"></div>
<script type="text/javascript">
scope.pagedata.nowckey = 0;  //状态标记
//刷新总数和总价
scope.pagedata.refresh=function(){
	scope.pagedata.showprice=scope.price(scope.pagedata.totalprice);
	scope.$evalAsync();
}
scope.pagedata.get_list=function(isfirst){
		var url='jy_meye/myshop/getlist/'
		if(isfirst){
			if(!scope.pagedata.params){
				scope.pagedata.params={};
			}
			scope.pagedata.goodslist=[];
			scope.pagedata.params.page=1;
			scope.pagedata.loaded=false;
		}else if(scope.pagedata.loaded || scope.pagedata.loading){
			return;
		}
		scope.pagedata.loading=true;
		$('#loading_show').show();
		if(typeof(url)!='object'){
			url=scope.tool.links(url);
		}
		var query=scope.made_query(scope.pagedata.params);
		if(url.query){
			url.query+='&'+query;
		}else{
			url.query=query;
		}
		//console.log('query');console.log(query);
		scope.get(url,function(res){
			console.log(res);
			scope.pagedata.loading=false;
			$('#loading_show').hide();
			if(res=='none'){
				scope.pagedata.loaded=true;
				return;
			}
			if(!Array.isArray(res)){
				var list=res.list?res.list:[]
			}else{
				var list=res
			}
			if(list.length==0 || (scope.pagedata.psize && list.length<scope.pagedata.psize)){
				scope.pagedata.loaded=true;
			}
			if(!scope.pagedata.goodslist || isfirst){
				scope.pagedata.goodslist=[];
			}
			list.forEach(function(row){
				scope.pagedata.goodslist.push(row);
			});
			scope.pagedata.params.page++;
			scope.$evalAsync();
		});
}
scope.pagedata.get_list(true);
scope.pagedata.scroll_bottom=function(){
	scope.pagedata.get_list();
}
//减少
scope.pagedata.minus=function(g,iscart){
	if(iscart){
		g.carttotal=g.total
		g.cartid=g.id
		g.id=g.goodsid
	}
	if(g.carttotal<=0){
		return false;
	}
	scope.post_json('jy_weishop/member.cart/minus/',{'getlist':true,'id':g.cartid},function(res){
			g.carttotal--;
			if(iscart){
				g.total--
				for (j = 0; j < scope.pagedata.goodslist.length; j++) {
						if(scope.pagedata.goodslist[j].id==g.id){
							scope.pagedata.goodslist[j].carttotal=g.total
						}
				}
				for (var i = 0; i < scope.pagedata.category.length; i++) {
						if(scope.pagedata.category[i].id==g.pcate){
							scope.pagedata.category[i].total--
						}
				}
			}else{
				scope.pagedata.category[scope.pagedata.nowckey].total--
			}
			scope.pagedata.carts=res.list
			scope.pagedata.allnum--
			scope.pagedata.totalprice-=g.price*1
			scope.pagedata.refresh();
			
	});
}
//增加
scope.pagedata.plus=function(g,iscart){
	if(iscart){
		g.carttotal=g.total
		g.id=g.goodsid
		if(g.optionid>0){
			if(g.carttotal>=g.options.stock){
				scope.message('不能再添加了，已超过库存！','error');
				return false;
			}
		}else{
			if(g.carttotal>=g.goodstotal){
				scope.message('不能再添加了，已超过库存！','error');
				return false;
			}
		}
	}else{
		g.optionid=0;
		if(g.carttotal>=g.total){
			scope.message('不能再添加了，已超过库存！','error');
			return false;
		}
	}	
	scope.post_json('jy_weishop/member.cart/addtocart/',{'getlist':true,'goodsid':g.id,'optionid':g.optionid},function(res){
			g.carttotal++;
			if(iscart){
				g.total++
				var category=scope.pagedata.category
				for (j = 0; j < scope.pagedata.goodslist.length; j++) {
						if(scope.pagedata.goodslist[j].id==g.id){
							scope.pagedata.goodslist[j].carttotal=g.total
						}
				}
				for (var i = 0; i < scope.pagedata.category.length; i++) {
						if(scope.pagedata.category[i].id==g.pcate){
							scope.pagedata.category[i].total++
						}
				}
			}else{
				scope.pagedata.category[scope.pagedata.nowckey].total++
			}
			if(res!='success'){
				g.cartid=res.id;
				scope.pagedata.carts=res.list
			}
			scope.pagedata.allnum++
			scope.pagedata.totalprice+=g.price*1
			scope.pagedata.refresh();
	});
}
//减少
scope.pagedata.sp_minus=function(){
	var g =scope.pagedata.g;
	if(g.carttotal<=0){
		return false;
	}
	scope.post_json('jy_weishop/member.cart/minus/',{'getlist':true,'id':g.cartid,'optionid':g.options.id},function(res){
			g.carttotal--;
			if(g.post[g.options.id].num<=0){
				return false;
			}
			scope.pagedata.carts=res.list
			g.post[g.options.id].num--;
			scope.pagedata.category[scope.pagedata.nowckey].total--
			scope.pagedata.goodslist[scope.pagedata.nowgkey]=g
			scope.pagedata.allnum--
			scope.pagedata.totalprice-=g.options.price*1
			scope.pagedata.refresh();
			
	});
}
//增加
scope.pagedata.sp_plus=function(){
	var g =scope.pagedata.g;
	if(g.carttotal>=g.options.stock){
		scope.message('不能再添加了，已超过库存！','error');
		return false;
	}
	scope.post_json('jy_weishop/member.cart/addtocart/',{'getlist':true,'goodsid':g.id,'optionid':g.options.id},function(res){
			
			g.carttotal++;
			g.post[g.options.id].num++;
			if(res!='success'){
				g.cartid=res.id;
				scope.pagedata.carts=res.list
			}
			scope.pagedata.category[scope.pagedata.nowckey].total++
			scope.pagedata.goodslist[scope.pagedata.nowgkey]=g
			scope.pagedata.allnum++
			scope.pagedata.totalprice+=g.options.price*1
			scope.pagedata.refresh();
	});
}
//选择
scope.pagedata.get_optionsid=function(){
	var specid = scope.pagedata.g.specid;
	specid = specid.join('_');
	scope.post_json('jy_weishop/goods.detail/get_optionsid/',{'goodsid':scope.pagedata.g.id,'specid':specid,'isdish':1},function(res){
			var optionsid=res.options.id;
			scope.pagedata.g.options=res.options;
			scope.pagedata.g.selespename=res.selespename;
			if(!scope.pagedata.g.post[optionsid]){
				scope.pagedata.g.post[optionsid]={}
				scope.pagedata.g.post[optionsid]={
					'num':scope.pagedata.g.post[optionsid].num?scope.pagedata.g.post[optionsid].num:res.carttotal,
					'title':res.selespename,
				}
			}
			
			scope.$evalAsync();
	});
}
scope.pagedata.refresh();
 $('.plus').on('click', function () {
	var cart = $('.quick-cart');
        var imgtodrag = $(this).parent('.quick-item').find("img").eq(0);
        if (imgtodrag) {
            var imgclone = imgtodrag.clone()
                .offset({
                top: imgtodrag.offset().top,
                left: imgtodrag.offset().left
            })
                .css({
                'opacity': '0.5',
                    'position': 'absolute',
                    'height': '2rem',
                    'width': '2rem',
                    'z-index': '100'
            })
                .appendTo($('body'))
                .animate({
                'top': cart.offset().top + 10,
                    'left': cart.offset().left + 10,
                    'width': 75,
                    'height': 75
            }, 1000, 'easeInOutExpo');
            
            imgclone.animate({
                'width': 0,
                    'height': 0
            }, function () {
                $(this).detach()
            });
        }
});
require(['bootstrap', 'hammer'], function($, Hammer){
		$('#carousel-container').carousel();
		var mc = new Hammer($('#carousel-container').get(0));
		mc.on("panleft", function(ev) {
			$('#carousel-container').carousel('next');
		});
		mc.on("panright", function(ev) {
			$('#carousel-container').carousel('prev');
		});
});
</script>